﻿using System.Linq;
using BankCreditPortfolio.DAL.Entities;

namespace BankCreditPortfolio.DAL.Services
{
    public class RoleService : DataService<Role>
    {
        public Role GetRoleByTitle(string roleTitle)
        {
            var filteredQuery = this.CreateQuery().Where(x => x.Title == roleTitle);
            return filteredQuery.Count() > 0 ? filteredQuery.Single() : null;
        }

        public override bool Save(ref Role entity)
        {
            if (GetRoleByTitle(entity.Title) == null)
                return base.Save(ref entity);
            return false;
        }
    }
}